//
//  JKAccountManager.swift
//  ZhiHuDaily-Swift
//
//  Created by albert on 2018/3/13.
//  Copyright © 2018年 安永博. All rights reserved.
//

import UIKit

class JKAccountManager: NSObject {

    /** 单例 */
    public static let shared = JKAccountManager()
    
    /** 登录 */
    public class func loginWithUserName(userName: String, password: String, finish: ((_ error: Error?) -> Void)) {
        
        // 在这里处理帐号和密码。暂时只要输入就登录吧
        UserDefaults.standard.set(userName, forKey: JKUserNameKey)
        UserDefaults.standard.set(true, forKey: JKIsLoginKey)
        UserDefaults.standard.synchronize()
        
        finish(nil)
    }
    
    /** 登出 */
    public class func logout() {
        
        UserDefaults.standard.removeObject(forKey: JKUserNameKey)
        UserDefaults.standard.set(false, forKey: JKIsLoginKey)
        UserDefaults.standard.synchronize()
    }
    
    
    public var userName: String? {
        
        return UserDefaults.standard.string(forKey: JKUserNameKey)
    }
    
    
    public var isLogin: Bool {
        
        return UserDefaults.standard.bool(forKey: JKIsLoginKey)
    }
    
    
    
    // MARK: - 默认头像占位图
    private let placeHolder_ = UIImage(named: "Setting_Avatar")?.jk_circleImage()
    
    public var headerIconPlaceHolder: UIImage? {
        
        return placeHolder_
    }
}
